import 'package:flutter/material.dart';
import 'package:device_info/device_info.dart';
class DevicesPage extends StatefulWidget {
  DevicesPage({Key key}) : super(key: key);

  @override
  _DevicesPageState createState() => _DevicesPageState();
}

class _DevicesPageState extends State<DevicesPage> {

  String device;

  @override
  initState(){
    super.initState();
    this._getInfo();
  }

  _getInfo() async {
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
    print('设备号 on ${androidInfo.androidId}');  // e.g. "Moto G (4)"

    setState(() {
      device = androidInfo.androidId;
    });
     // IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
    // print('Running on ${iosInfo.utsname.machine}');  // e.g. "iPod7,1"
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("获取设备信息"),
      ),
      body: Center(
        child: Text(
          "${this.device}"
        ),
      ),
    );
  }
}
